<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登入 - PsychologicalAdmin</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/admin.css" media="all">
    <link rel="stylesheet" href="/css/login.css" media="all">
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>PsychologicalAdmin</h2>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form" >
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-username"></label>
                <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required"
                       placeholder="密码" class="layui-input">
            </div>

            <div class="layui-form-item" style="margin-bottom: 20px;">
                <!--<input type="checkbox" name="remember" lay-skin="primary" title="记住密码">-->
                <!--<div class="layui-unselect layui-form-checkbox" lay-skin="primary">-->
                    <!--<span>记住密码</span>-->
                    <!--<i class="layui-icon layui-icon-ok"></i>-->
                <!--</div>-->
                <a href="forget.html" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？</a>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="user-login-submit">登 入</button>
            </div>
        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">
        <p>© 2019 fjutsl.top</a></p>
    </div>
</div>

<script src="/layui/layui.js"></script>
<script>

    layui.use(['form', 'layer'], function () {
        const $ = layui.$;
        const layer = layui.layer;
        const form = layui.form;

        //监听提交
        form.on('submit(user-login-submit)', function (msg) {
            const data = msg.field;
            //请求登入接口
            $.ajax({
                method: "post",
                url: "/admin/login",
                data,
                success(res){
                    console.log(res)
                    //请求成功后，写入 access_token
                    // layui.data(setter.tableName, {
                    //     key: setter.request.tokenName
                    //     , value: res.data.access_token
                   // console.log(res.status)
                    if(res.status === 200){
                        // layer.msg(res.msg, {
                        //     anim: 5,
                        //     time: 1500
                        // })

                        //登入成功的提示与跳转
                        layer.msg(res.msg, {
                            offset: '15px'
                            ,icon: 1
                            ,time: 1000
                        }, function(){
                            location.href = '/admin/views'; //后台主页
                        });

                    }else {
                        layer.msg(res.msg, {
                            anim: 5,
                            time: 1200
                        })
                    }
                },
                fail(err){
                    layer.msg("请求超时", {
                        anim: 5,
                        time: 1500
                    })
                }
            })
        });
    });
</script>
</body>
</html>